home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / os2 / fm2_240.zip / EXAMPLE.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-08  |  2KB  |  92 lines

  1. /*
  2.  * Example of how a rexx file can operate on a list file created by
  3.  * FM/2 (the list file should contain filenames only).
  4.  *
  5.  * This example can be editted at the boxed comment area below and
  6.  * used with FM/2 Commands containing the %! metastring.
  7.  *
  8.  * Call as "%c /C <drive:\path\>EXAMPLE.CMD %!" (exclude quotes)
  9.  *  (for example:  %c /C e:\fm2\EXAMPLES.CMD %!)
  10.  */
  11.  
  12. /* suppress echo from "batch" commands */
  13. '@Echo off'
  14. /* clear screen (GPs). */
  15. '@cls'
  16.  
  17. /* get name of listfile from command line. */
  18. parse arg listfile
  19.  
  20. /* if no listfile name was given, issue help and exit. */
  21. if listfile = '' then
  22. do
  23.   say 'Give the name of a listfile as an argument to this REXX script.'
  24.   exit
  25. end
  26.  
  27. /* for debugging purposes: */
  28. say 'Name of our listfile is "'listfile'".'
  29.  
  30. /* see if the listfile given exists -- exit with error message if not */
  31. rc = stream(listfile,'C','QUERY EXISTS')
  32. if rc = '' then
  33. do
  34.   say 'File "'listfile'" doesn''t exist.'
  35.   exit
  36. end
  37.  
  38. /* attempt to open the listfile given on the command line */
  39. rc = stream(listfile,'C','OPEN')
  40.  
  41. /* if open was successful, enter loop */
  42. if rc = 'READY:' then
  43. do
  44.  
  45.   counter = 0     /* initialize counter */
  46.  
  47.   /* read each line of the listfile into filename */
  48.   do while lines(listfile) = 1
  49.     filename = linein(listfile)
  50.  
  51.     /* remove any leading/trailing blanks */
  52.     filename = strip(filename,'b')
  53.  
  54.     /* process only non-blank strings */
  55.     if filename \= '' then
  56.  
  57.  
  58.     /*************************************************************
  59.      * here you would do something to/with the file in filename. *
  60.      * since this is only an example, we'll just print the name. *
  61.      *************************************************************/
  62.  
  63.     do
  64.       say filename          /* useful for debugging  */
  65.       counter = counter + 1 /* count files processed */
  66.     end
  67.  
  68.     /*************************************************************
  69.      * end of area where you'd do your special processing.       *
  70.      *************************************************************/
  71.  
  72.   end
  73.  
  74.   /* close the listfile. */
  75.   rc = stream(listfile,'C','CLOSE')
  76.  
  77.   /* remove the listfile -- checks to disallow wildcards in name (GPs). */
  78.   if (pos('*',listfile) = 0) & (pos('?',listfile) = 0) then
  79.   do
  80.     'del "'listfile'" 1>NUL 2>NUL'
  81.   end
  82.  
  83. end
  84. else
  85. do
  86.   say 'Error opening "'listfile'".'
  87.   exit
  88. end
  89.  
  90. /* we're done. */
  91. say '  **I processed 'counter' objects.'
  92.